package com.ymx.darling.dialect.keygenerator;

import com.ymx.darling.bean.entity.BeanInfo;
import com.ymx.darling.bean.entity.BeanInfoManager;
import com.ymx.darling.bean.entity.id.IdType;
import com.ymx.darling.bean.sql.Statement;

import java.sql.PreparedStatement;
import java.util.List;

/**
 * 基于雪花算法生成分布式id
 * @author 爱Java的小于
 */
public class AssignKeyGenerator implements KeyGenerator {

    @Override
    public void processBefore(List<Object> entityList, Statement statement) {
        BeanInfo beanInfo = BeanInfoManager.getBeanInfo(entityList.get(0).getClass());
        entityList.forEach(entity -> BeanInfoManager.doPrimaryKeyFill(entity, beanInfo));
    }

    @Override
    public void processAfter(List<Object> entityList, Statement statement, PreparedStatement preparedStatement) {
    }

    @Override
    public IdType getIdType() {
        return IdType.ASSIGN;
    }
}
